﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Threading;
using System.Windows.Threading;
using StopLight.Interfaces;

namespace StopLight.Services
{
    public class RealTimeTimerService : IStoplightTimerService 
    {
        private DispatcherTimer timer;

        public event EventHandler Expired;

        public RealTimeTimerService() {
            timer = new DispatcherTimer();
            timer.Tick += OnTick;
        }

        public TimeSpan Duration {
            get { return timer.Interval; }
            set { timer.Interval = value; }
        }

        public void Start() {
            timer.Start();
        }

        private void OnTick(object sender, EventArgs e) {
            timer.Stop();
            if (Expired != null)
                Expired(this, EventArgs.Empty);
        }

    }
}
